from typing import Union, List
from datetime import datetime
from pydantic import Field
from fastapi import Query

from admin.schemas.base import CamelModel


class UserListIn(CamelModel):
    name: Union[str, None] = Field(default=None, title="用户名")
    email: Union[str, None] = Field(default=None, title="邮箱")

    class Config:
        from_attributes = True
        field_operator_mapping = {
            "name": "LIKE",
            "email": "LIKE",
        }


class UserDetailIn(CamelModel):
    id: int = Query(..., title="用户ID", gt=0)


class UserAddIn(CamelModel):
    name: str = Field(..., title="用户名")
    email: str = Field(..., title="邮箱")


class UserEditIn(UserAddIn):
    id: int = Field(..., title="用户ID", gt=0)


class UserDelIn(CamelModel):
    id: int = Field(..., title="用户ID", gt=0)


class UserOut(CamelModel):
    id: int
    name: str
    email: str
    created_at: Union[datetime, None] = None

    class Config:
        from_attributes = True
